﻿//===============================================================================
//	Backpack.h
//	用户背包
//===============================================================================

#pragma once

#include <cstdint>
#include <array>

//-------------------------------------------------------------------------------
//	背包物品类
struct BackpackItem
{
	uint32_t m_id;
	int16_t m_count;
	int16_t m_max_count;
	int16_t m_types;
	char m_uuid[48];

	BackpackItem(void);

	void Clear(void);

	BackpackItem& operator=(const BackpackItem& rhs);
};

//-------------------------------------------------------------------------------
class Backpack
{
	static const int16_t max_backpack_item_count = 1024;

private:
	std::array<BackpackItem, max_backpack_item_count> m_items_array;
	int16_t m_end_pos;

public:
	Backpack(void);
	~Backpack(void);

public:
	bool Initialize(void);
	int16_t GetItemCountByItemId(uint32_t id);
	int16_t GetItemIndexByItemId(uint32_t id);
	void SetItemCountByItemId(uint32_t id, int16_t count);
	void SetItemInfo(uint32_t id, int16_t count, int16_t maxCount, int16_t types, std::string uuid);
	bool DeleteItemByItemId(uint32_t id);

	std::string GetItemListJsonString(void);
	std::string GetItemListJsonStringByTypes(uint16_t types);
};